package ee.videorentalstore.users;

import java.util.HashSet;
import java.util.Set;
import ee.videorentalstore.users.types.Customer;

public class UsersDatabase 
{
	private static UsersDatabase instance = null;
	private Set<User> filmRentalStoreUsers = new HashSet<User>();
	private Set<Customer> filmRentalStoreCustomers = new HashSet<Customer>();
	
	private UsersDatabase()
	{
		
	}
	
	public static UsersDatabase getInstance()
	{
		if (instance == null)
		{
			instance = new UsersDatabase();
		}
		return instance;
	}
	
//------------------START OF USER METHODS--------------------------------------	
	
	public void registerANewUser(User user)
	{
		filmRentalStoreUsers.add(user);
	}
	
	
	public boolean getWhetherUserExists(User user)
	{
		return filmRentalStoreUsers.contains(user);
	}
	
	
	public boolean getWhetherUserExistsByID(int userIDToLookFor)
	{
		boolean doesUserExists = false;
		for (User user : filmRentalStoreUsers)
		{
			if (user.getUserID() == userIDToLookFor)
			{
				doesUserExists = true;
				break;
			}
		}
		return doesUserExists;
	}
	
	
	public User getUser(int userIDToLookFor)
	{
		User userToReturn = null;
		for (User user : filmRentalStoreUsers)
		{
			if (user.getUserID() == userIDToLookFor)
			{
				userToReturn = user;
				break;
			}
		}
		return userToReturn;
	}
	
	
	public Set<User> getAllUsers()
	{
		return filmRentalStoreUsers;
	}
	
//------------------END OF USER METHODS----------------------------------------	
	
//------------------START OF CUSTOMER METHODS----------------------------------	
	public void registerANewCustomer(Customer customer)
	{
		filmRentalStoreCustomers.add(customer);
	}
	
	
	public boolean getWhetherCustomerExists(Customer customer)
	{
		return filmRentalStoreCustomers.contains(customer);
	}
	
	
	public boolean getWhetherCustomerExistsByID(int customerIDToLookFor)
	{
		boolean doesCustomerExists = false;
		for (User user : filmRentalStoreUsers)
		{
			if (user.getUserID() == customerIDToLookFor)
			{
				doesCustomerExists = true;
				break;
			}
		}
		return doesCustomerExists;
	}
	
	
	public Customer getCustomer(int customerIDToLookFor)
	{
		Customer customerToReturn = null;
		for (Customer customer : filmRentalStoreCustomers)
		{
			if (customer.getUserID() == customerIDToLookFor)
			{
				customerToReturn = customer;
				break;
			}
		}
		return customerToReturn;
	}
	
	
	public Set<Customer> getAllCustomers()
	{
		return filmRentalStoreCustomers;
	}
//------------------END OF CUSTOMER METHODS------------------------------------
}
